package o;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.productpurchase.api.ProductDetailBean;
import com.huawei.appgallery.productpurchase.impl.cache.DpsProductDetail;
import java.util.ArrayList;
import java.util.List;
import o.crh.b;

public class crw implements cfc {
    private boolean ʻ = false;
    private Handler ʼ = new Handler(this, Looper.getMainLooper()) {
        final /* synthetic */ crw ˏ;

        public void handleMessage(Message message) {
            if (message.what == 1 && this.ˏ.ˏ != null && !this.ˏ.ˏ.isShowing() && !ActivityUtil.isAcitivtyNotValid(this.ˏ.ˏ.getContext())) {
                try {
                    this.ˏ.ˏ.show();
                    ayw.ˊ(this.ˏ.ˏ.getWindow());
                } catch (Exception e) {
                    crf.ˎ.ˊ("ProductAppInfoListener", "handleMessage, ex = " + e.toString());
                }
            }
        }
    };
    private Context ˊ;
    private ProductDetailBean ˋ;
    private bnh ˎ;
    private djl ˏ;
    private DpsProductDetail ॱ;

    public class e implements cfd {
        final /* synthetic */ crw ˋ;
        private int ˎ;

        public e(crw o_crw, int i) {
            this.ˋ = o_crw;
            this.ˎ = i;
        }

        public void ˋ(int i, int i2, List<cfe> list) {
            if (i2 != 0 || i != 0 || this.ˋ.ʻ) {
                cro.ˏ().ˏ(2);
            } else if (list == null || list.size() <= 0) {
                cro.ˏ().ˏ(2);
            } else if (((cfe) list.get(0)).ˏ == 1) {
                ˎ();
            } else {
                ˋ();
            }
            this.ˋ.ˏ();
        }

        private void ˎ() {
            crf.ˎ.ˎ("ProductAppValidateListener", "Legal APP");
            boolean ˊ = csr.ˊ();
            csi.ˋ(12);
            if (ˊ) {
                crr.ˊ(this.ˋ.ˊ, this.ˋ.ˋ, this.ˋ.ॱ, this.ˎ);
            } else {
                crr.ˎ(this.ˋ.ˊ, this.ˋ.ˋ, this.ˋ.ॱ, this.ˎ);
            }
        }

        private void ˋ() {
            crf.ˎ.ˎ("ProductAppValidateListener", "Not legal APP");
            if (cso.ˏ(this.ˎ)) {
                crr.ˎ(this.ˋ.ˊ, this.ˋ.ˋ, b.ˏॱ, b.ˎ, this.ˎ);
            } else {
                crr.ˎ(this.ˋ.ˊ, this.ˋ.ˋ, b.ˋॱ, b.ॱ);
            }
        }
    }

    public crw(Context context, ProductDetailBean productDetailBean, DpsProductDetail dpsProductDetail) {
        this.ˊ = context;
        this.ˋ = productDetailBean;
        this.ॱ = dpsProductDetail;
        this.ˎ = (bnh) fho.ˏ().ˋ("DownloadEngine").ॱ(bnh.class);
    }

    public void ॱ(int i, int i2, @Nullable List<cfa> list) {
        if (i2 != 0 || i != 0) {
            cro.ˏ().ˏ(1);
            crf.ˎ.ˏ("ProductAppInfoListener", "Fail to get application download information.");
        } else if (list == null || list.size() <= 0) {
            cro.ˏ().ˏ(2);
        } else {
            cfa o_cfa = (cfa) list.get(0);
            if (this.ˋ == null || o_cfa == null) {
                cro.ˏ().ˏ(2);
                return;
            }
            int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(o_cfa.ˏ);
            crf.ˎ.ˋ("ProductAppInfoListener", "appStatus = " + ˋ);
            ˊ(o_cfa);
            switch (ˋ) {
                case -2:
                case 0:
                case 3:
                case 4:
                    ˏ(ˋ);
                    return;
                case 1:
                    ˎ(ˋ);
                    return;
                case 8:
                case 10:
                case 11:
                    cso.ˊ(this.ˊ, b.ʻ);
                    cro.ˏ().ˏ(8);
                    return;
                default:
                    cso.ˎ(this.ˊ, b.ॱˋ, this.ˋ.v_());
                    cro.ˏ().ˏ(2);
                    return;
            }
        }
    }

    private void ˊ(cfa o_cfa) {
        this.ˋ.ˊॱ(o_cfa.ॱᐝ);
        this.ˋ.ॱˊ(o_cfa.ॱˊ);
        this.ˋ.ˏॱ(o_cfa.ˋ);
        this.ˋ.ˋॱ(o_cfa.ॱ);
        this.ˋ.ˏˎ(o_cfa.ˏ);
        this.ˋ.ˏ(o_cfa.ͺ);
        this.ˋ.ॱ(Long.parseLong(o_cfa.ᐝ));
        this.ˋ.ˎ(o_cfa.ᐝॱ);
        this.ˋ.ˋᐝ(o_cfa.ˎ);
        this.ˋ.ˋ(o_cfa.ॱॱ);
    }

    private void ˏ(int i) {
        int i2 = 1;
        SessionDownloadTask ॱ = ॱ(this.ˋ.ॱـ());
        if (ॱ != null) {
            int ˈ = ॱ.ˈ();
            crf.ˎ.ˋ("ProductAppInfoListener", "appstatus = " + i);
            switch (ˈ) {
                case 2:
                case 5:
                    csi.ˋ(0);
                    cso.ˊ(this.ˊ, b.ʻ);
                    break;
                case 6:
                case 7:
                    csi.ˋ(0);
                    cso.ˊ(this.ˊ, b.ˊॱ);
                    break;
            }
        }
        i2 = 0;
        if (i2 == 0) {
            switch (i) {
                case -2:
                    crr.ˎ(this.ˊ, this.ˋ, b.ॱˊ, b.ॱ, i);
                    return;
                case 0:
                case 3:
                case 4:
                    ॱ(i);
                    return;
                default:
                    cro.ˏ().ˏ(2);
                    return;
            }
        }
        cro.ˏ().ˏ(8);
    }

    @Nullable
    private SessionDownloadTask ॱ(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        List<SessionDownloadTask> ˎ = ˎ(str);
        if (!CollectCheck.isEmpty(ˎ)) {
            for (SessionDownloadTask sessionDownloadTask : ˎ) {
                int ˌ = sessionDownloadTask.ˌ();
                if (ˌ != 9 && ˌ != 10) {
                    return sessionDownloadTask;
                }
            }
        }
        return null;
    }

    @Nullable
    private List<SessionDownloadTask> ˎ(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        List<SessionDownloadTask> arrayList = new ArrayList();
        for (SessionDownloadTask sessionDownloadTask : this.ˎ.ॱ()) {
            if (str.equals(sessionDownloadTask.ˊˊ())) {
                arrayList.add(sessionDownloadTask);
            }
        }
        return arrayList;
    }

    private void ˎ(int i) {
        crr.ˎ(this.ˊ, this.ˋ, b.ॱˊ, b.ॱ, i);
    }

    private void ॱ(int i) {
        PackageManager packageManager = this.ˊ.getPackageManager();
        if (packageManager != null) {
            try {
                if (this.ˋ != null) {
                    PackageInfo packageInfo = packageManager.getPackageInfo(this.ˋ.ॱـ(), 1);
                    if (packageInfo != null) {
                        int i2 = packageInfo.versionCode;
                        if (cgy.ˎ(this.ˋ.ʽ()) || i2 >= Integer.parseInt(this.ˋ.ʽ())) {
                            ˎ(packageInfo, i);
                            return;
                        } else {
                            ˋ(i);
                            return;
                        }
                    }
                    cro.ˏ().ˏ(2);
                    return;
                }
            } catch (NameNotFoundException e) {
                crf.ˎ.ˏ("ProductAppInfoListener", "no package: " + this.ˋ.ॱـ());
                cro.ˏ().ˏ(2);
                return;
            }
        }
        cro.ˏ().ˏ(2);
    }

    private void ˋ(int i) {
        if (cso.ˏ(i)) {
            crr.ˎ(this.ˊ, this.ˋ, b.ˏॱ, b.ˎ, i);
            return;
        }
        cso.ˎ(this.ˊ, b.ॱˋ, this.ˋ.v_());
        cro.ˏ().ˏ(2);
        crf.ˎ.ˋ("ProductAppInfoListener", "The version of application is low.");
    }

    private void ˎ(PackageInfo packageInfo, int i) {
        crf.ˎ.ˋ("ProductAppInfoListener", "Check the legality of the third app installed by consumer.");
        ˊ();
        List arrayList = new ArrayList();
        List arrayList2 = new ArrayList();
        arrayList.add(packageInfo.packageName);
        arrayList2.add(cso.ˎ(packageInfo.applicationInfo.sourceDir));
        ((cfg) cdb.ॱ(cfg.class)).checkAppValidate(arrayList, arrayList2, new e(this, i));
    }

    private void ˊ() {
        this.ˏ = new djl(this.ˊ);
        this.ˏ.setCancelable(true);
        this.ˏ.ˋ(this.ˊ.getString(b.ˊˊ));
        this.ˏ.setCanceledOnTouchOutside(false);
        this.ˏ.setOnCancelListener(new OnCancelListener(this) {
            final /* synthetic */ crw ˋ;

            {
                this.ˋ = r1;
            }

            public void onCancel(DialogInterface dialogInterface) {
                this.ˋ.ʻ = true;
            }
        });
        this.ʼ.sendMessageDelayed(this.ʼ.obtainMessage(1), 500);
    }

    public void ˏ() {
        this.ʼ.removeMessages(1);
        if (this.ˏ != null && this.ˏ.isShowing()) {
            try {
                this.ˏ.dismiss();
                this.ˏ = null;
            } catch (IllegalArgumentException e) {
                crf.ˎ.ˊ("ProductAppInfoListener", "Loading Dialog IllegalArgumentException");
            }
        }
        this.ʻ = false;
    }
}
